import * as types from '../constants/recruitTypes'

const initialState = {
  isSuccess: false,
  errMsg: '',
  list: [],
  stat: {
    apprenticeNum: 0,
    effectiveApprenticeNum: 0,
    discipleNum: 0 // 如何计算有效的徒弟
  }
}

export default function recruit (state = initialState, action) {
  switch (action.type) {
    case types.RECRUIT_IN_SUCCESS:
      return {
        ...state,
        list: action.data.apprenticeList,
        stat: {
          apprenticeNum: action.data.apprenticeNum,
          effectiveApprenticeNum: action.data.effectiveApprenticeNum,
          discipleNum: action.data.discipleNum
        },
        isSuccess: 'success'
      }
      break
    case types.RECRUIT_IN_ERROR:
      return {
        ...state,
        errMsg: action.err,
        isSuccess: 'err'
      }

    default:
      return state
  }
}
